import java.io.*;

/**
 * Author: Daniel Michalski
 * Date: 28.03.13
 */

public class SerializationDemo {
    private static final String FILE_NAME = "serial";

    public static void main(String[] args) {
        try ( ObjectOutputStream objOStr =
                new ObjectOutputStream(new FileOutputStream(FILE_NAME)))
        {
            MyClass object1 = new MyClass("Witaj", -7, 2.7e10);
            System.out.println(object1);
            objOStr.writeObject(object1);
        } catch (IOException ex) {
            System.out.println("Wyjątek w czasie serializacji: " + ex);
        }

        try ( ObjectInputStream objIStr =
                new ObjectInputStream(new FileInputStream(FILE_NAME)))
        {
            MyClass object2 = (MyClass) objIStr.readObject();
            System.out.println(object2);
        } catch (Exception ex) {
            System.out.println("Wyjątek w czasie deserializacji: " + ex);
        }
    }
}
